const MusicHttp = require("../../utils/MusicHttp")
const { handleNum, handleLength } = require("../../utils/util")
Page({


  data: {
    name: "",
    coverImgUrl: "",
    description: "",
    tags: "",
    shareCount: "",
    playCount: ""
  },
  handleBof(event) {
    var {aid} = event.currentTarget.dataset
    wx.navigateTo({
      url: `/pages/bof/bof?id=${aid}`,
    })
  },
  onLoad:  function (options) {
    console.log(options)
    var { id } = options
    var url = `http://47.108.197.28:3000/playlist/detail?id=${id}`
    wx.request({
      url,
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res)=>{
        console.log(res.data.playlist);
        var playlist = res.data.playlist;
        var playCount = playlist.playCount;
        var description = playlist.description
        var tracks = res.data.playlist.tracks;
        var list = []
        tracks.forEach(item => {
          var { al } = item;
          list.push({
            id: al.id,
            name: al.name,
            picurl: al.picUrl,
          })
        })
        this.setData({
          list
        })
        this.setData({
          trackCount: playlist.trackCount,
          name: playlist.name,
          coverImgUrl: playlist.coverImgUrl,
          description: handleLength(description),
          tags: playlist.tags,
          shareCount: playlist.shareCount,
          playCount: handleNum(playCount),
          subscribedCount: playlist.subscribedCount
        })
      },
    });
  },
})
